package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DelayedMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/4 23:19
 */
@Component
public class DelayReceiver {

    @SneakyThrows
    @RabbitListener(queues = DelayedMqConfig.queue_delay_1)
    public void get(String msg, Message message, Channel channel) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("接收消息的时间\t" + simpleDateFormat.format(new Date()) + "消息：\t" + msg);
        //    手动确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
